package com.aacar.controller.common;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.dto.Header;
import com.aacar.dto.PageDto;
import com.aacar.service.BrandService;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.AllBrandVo;
import com.aacar.vo.HotBrandVo;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;

/**
 * 品牌
 * @author wangh
 *
 */
@RestController
@RequestMapping("/brand")
public class BrandController {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private BrandService brandService;
	
	
	//获取热门品牌车子
	@RequestMapping(value = "/getHotBrand/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getHotBrand(@RequestHeader(value="mobilehead") String mobilehead) {
		logger.info("request:/getHotBrand/0");
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<HotBrandVo> hotBrand = this.brandService.getHotBrandVo();
		Map<String,Object> resultMap = Maps.newConcurrentMap();
		resultMap.put("info", hotBrand);
		return ResultInfoUtil.setSuccessInfo(resultMap,header.getService());
	}
	
	//获取所有品牌车子
	@RequestMapping(value = "/getAllBrand/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getAllBrand(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody PageDto pageDto) {
		logger.info("request:/getAllBrand/0");
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		//1.获取所有品牌
		List<AllBrandVo> hotBrand = this.brandService.getAllBrandVo(pageDto);
		//2.获取所有品牌数量
		int totalCount = this.brandService.getgetAllBrandCount();
		Map<Object,Object> map = new LinkedHashMap<>();
		map.put("totalCount", totalCount);
		map.put("info", hotBrand);
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	}
	
}
